<?php

declare(strict_types=1);

namespace DreamCat\ControllerParamGen\Annotation;

use Attribute;
use JetBrains\PhpStorm\ExpectedValues;
use JetBrains\PhpStorm\Immutable;

/**
 * 控制器参数类型
 * @author vijay
 */
#[Attribute(Attribute::TARGET_PARAMETER)]
#[Immutable]
class CtlParamType
{
    /** @var int 请求体 */
    public const TYPE_REQUEST_BODY = 1;
    /** @var int url中的占位符 */
    public const TYPE_PATH_VARIABLE = 2;
    /** @var int get参数 */
    public const TYPE_GET_PARAM = 3;
    /** @var int header参数 */
    public const TYPE_HEADER = 4;
    /** @var int cookie参数 */
    public const TYPE_COOKIE = 5;

    /**
     * @param int $type 参数类型
     * @param ?string $path 路径，全体使用null，多级用/分隔
     */
    public function __construct(
        #[ExpectedValues(valuesFromClass: CtlParamType::class)]
        private int $type = CtlParamType::TYPE_REQUEST_BODY,
        private ?string $path = null,
    ) {
        if (is_string($this->path)) {
            $this->path = trim($this->path);
        }
        if ($this->path === "") {
            $this->path = null;
        }
    }

    /**
     * @return int
     */
    public function getType(): int
    {
        return $this->type;
    }

    /**
     * @return ?string
     */
    public function getPath(): ?string
    {
        return $this->path;
    }
}

# end of file
